package com.nanhai.buddhist.college.module.study.controller.admin.qrcodeconfig;

import com.nanhai.buddhist.college.framework.common.pojo.CommonResult;
import com.nanhai.buddhist.college.module.study.controller.admin.attendanceleavereason.vo.AttendanceLeaveReasonCreateReqVO;
import com.nanhai.buddhist.college.module.study.controller.admin.attendancemanagementlog.vo.AttendanceManagementLogRespVO;
import com.nanhai.buddhist.college.module.study.controller.admin.qrcodeconfig.vo.QrCodeConfigCreateReqVO;
import com.nanhai.buddhist.college.module.study.controller.admin.qrcodeconfig.vo.QrCodeConfigRespVO;
import com.nanhai.buddhist.college.module.study.controller.admin.qrcodeconfig.vo.QrCodeConfigUpdateReqVO;
import com.nanhai.buddhist.college.module.study.controller.admin.studyadditionalcourses.vo.StudyAdditionalCoursesUpdateReqVO;
import com.nanhai.buddhist.college.module.study.convert.attendancemanagementlog.AttendanceManagementLogConvert;
import com.nanhai.buddhist.college.module.study.convert.qrcodeconfig.QrCodeConfigConvert;
import com.nanhai.buddhist.college.module.study.dal.dataobject.attendancemanagementlog.AttendanceManagementLogDO;
import com.nanhai.buddhist.college.module.study.dal.dataobject.qrcodeconfig.QrCodeConfigDO;
import com.nanhai.buddhist.college.module.study.service.qrcodeconfig.QrCodeConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.nanhai.buddhist.college.framework.common.pojo.CommonResult.success;

/**
 * @author AKai
 * @date 2022/9/13
 */
@Api(tags = "管理后台 - 设置二维码")
@RestController
@RequestMapping("/study/qrcode")
@Validated
public class QrCodeConfigController {

    @Resource
    private QrCodeConfigService qrCodeConfigService;

    @PostMapping("/create")
    @ApiOperation("创建二维码配置")
    public CommonResult<String> createQrCodeConfig(@Valid @RequestBody QrCodeConfigCreateReqVO createReqVO) {
        return success(qrCodeConfigService.createQrCodeConfig(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新二维码配置")
    public CommonResult<Boolean> updateAdditionalCourses(@Valid @RequestBody QrCodeConfigUpdateReqVO updateReqVO) {
        qrCodeConfigService.updateQrCodeConfig(updateReqVO);
        return success(true);
    }

/*
    @DeleteMapping("/delete")
    @ApiOperation("删除二维码配置")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('study:attendance-management-log:delete')")
    public CommonResult<Boolean> deleteAttendanceManagementLog(@RequestParam("id") String id) {
        qrCodeConfigService.deleteQrCodeConfig(id);
        return success(true);
    }*/

    @GetMapping("/get")
    @ApiOperation("获得二维码配置")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    public CommonResult<QrCodeConfigRespVO> getAttendanceManagementLog(String id) {
         QrCodeConfigDO qrCodeConfigDO = qrCodeConfigService.getAQrCodeConfig(id);
        return success(QrCodeConfigConvert.INSTANCE.convert(qrCodeConfigDO));
    }


}
